package com.example.demo.controller;


import com.example.demo.utils.PassToken;
import com.example.demo.utils.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class TextController {
    @Autowired
    RedisTemplate<String,Object> redisTemplate;

    @GetMapping("/text")
    public String text(){
        String s = (String) redisTemplate.opsForValue().get("name");

        return s;
    }

//    @PostMapping("/login")
//    public ServerResponse<String> login(@RequestBody LoginUser loginUser){
//        String storeCode = (String) redisTemplate.opsForValue().get("captcha_codes:"+loginUser.getUuid());
//        if(loginUser.getCode().equals(storeCode)) {
//            String id = loginUser.getUsername();
//            String pwd = loginUser.getPassword();
//            Map<String, String> map = new HashMap<>();
//            map.put("username", id);
//            map.put("password", pwd);
//            if (id.equals("admin") && pwd.equals("admin")) {
//                String token = JWTUtils.getToken(map);
//                return ServerResponse.createBySuccess(200, token, "登录成功");
//            }
//            return ServerResponse.createBySuccess(500, "", "账号或密码错误");
//        }
//        else{
//            return ServerResponse.createBySuccess(500,"","验证码错误");
//        }
//        }




    @PassToken
    @GetMapping("getStudent")
    public ServerResponse<String> getStudent(){
        return ServerResponse.createBySuccess(200,"","查询成功");
    }
//    @GetMapping("getInfo")
//    public ServerResponse<String> getInfo(HttpServletRequest request) {
//        String token = request.getHeader("Authorization");
//        String id = JWT.decode(token.substring(token.lastIndexOf(" ")+1)).getClaim("username").asString();
//        return ServerResponse.createBySuccess(200,id,"查询成功");
//    }

@PassToken
@GetMapping("/getBanners")
    public ServerResponse<List<String>> getBanners(){
    List<String> list = new ArrayList<>();
    list.add("/images/2.jpg");list.add("/images/3.jpg");list.add("/images/4.jpg");
        return ServerResponse.createBySuccess(200,list,"显示轮播图");
    }
}
